// import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/'
import ElementUI from 'element-ui'
import axios from 'axios'
import {checkCookie} from '@/utils/cookie'
import VueJsonp from 'vue-jsonp'
import {number} from '@/utils/numberDirective'
import '@/style/element-variables.scss'

Vue.config.productionTip = false

Vue.use(VueJsonp, 3000)

Vue.use(ElementUI)

Vue.directive('numbers', number)

axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'
axios.defaults.withCredentials = true
Vue.prototype.$axios = axios

router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requireAuth)) { // 判断该路由是否需要登录权限
    if (checkCookie()) { // 判断当前的token是否存在
      next()
    } else {
      next({
        path: '/login'
      })
    }
  } else {
    next()
  }
})

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
